﻿using System;
using System.Windows.Forms;
using AI.Fuzzy.Library;
using Sharp3DMath.Strokes;
using Sharp3DMath.Core;

namespace SketchRecognise
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            LRSS_SharpResult result = new LRSS_SharpResult();
            #region Tese Data
            //result.Add(new Sharp("Line",0.08));
            //result.Add(new Sharp("Rectangle", 0.18));
            //result.Add(new Sharp("Circles", 0.43));
            //result.Add(new Sharp("Ellipse", 0.32));
            //result.Add(new Sharp("Delete", 0.79));
            //result.Add(new Sharp("Diamond", 0.66));
            //result.Add(new Sharp("Arc", 0.55));
            //result.Add(new Sharp("Curve", 0.90));
            //result.Add(new Sharp("Pentacle", 0.01));
            //result.Add(new Sharp("Trapezia", 0.21));
            //result.Add(new Sharp("ConcentricHelix", 0.52));
            //result.Add(new Sharp("Spiral", 0.33));
            //result.Add(new Sharp("FoldLine", 0.68));
            //result.Add(new Sharp("Triangle", 0.45));
            //result.Sort();
            #endregion
            recogniseResultPanel1.LoadFrom(result);

        }

        private void sketchPaintControl1_SketchFinished(object sender, SketchPaintControl.SketchDrawingFinishedEventArgs e)
        {
            StrokeFeaturesBase featuresBase = new StrokeFeaturesBase();
            featuresBase.ComputeFeatures(e.Features);
            globalFeaturesPanel1.LoadFrom(featuresBase);
            
        }

        private void sketchPaintControl1_SketchRecogniseFinished(object sender, SketchPaintControl.SketchRecogniseFinishedEventArgs e)
        {
            #region
            //string ts = string.Empty;
            //foreach (var item in e.RecogniseResults)
            //{
            //    ts += item.FuzzyVariableName + " " + item.FuzzyTermName + " " + item.Value.ToString() + "\r\n";
            //}
            //System.Console.WriteLine(ts);
            #endregion
           
            LRSS_SharpResult sharpResult = new LRSS_SharpResult();
            e.RecogniseResults.RemoveAt(e.RecogniseResults.Count - 1);
            foreach (var item in e.RecogniseResults)
            {
                sharpResult.Add(new Sharp(item.FuzzyTermName,Math.Round(item.Value,2,MidpointRounding.ToEven)));
            }
            sharpResult.Sort();
            Console.WriteLine(sharpResult.ToString());
            recogniseResultPanel1.LoadFrom(sharpResult);
            tb_Top1_Type.Text = sharpResult[0].sharpName;
            tb_Top1_Value.Text = sharpResult[0].value.ToString();

            tb_Top2_Type.Text = sharpResult[1].sharpName;
            tb_Top2_Value.Text = sharpResult[1].value.ToString();

            tb_Top3_Type.Text = sharpResult[2].sharpName;
            tb_Top3_Value.Text = sharpResult[2].value.ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            sketchPaintControl1.IsShowBeautySharp = !sketchPaintControl1.IsShowBeautySharp;
            sketchPaintControl1.IsShowOriginalSharp = !sketchPaintControl1.IsShowOriginalSharp;
            Invalidate(true);
        }
    }
}
